<fieldset>
	<legend>Danh sách "sách"</legend>
	<form class="well form-search">
	    <a class="btn btn-primary" href="<?php echo $this->config->base_path; ?>/librarian/book/create">Thêm sách</a>
        <div class="right">
            <input type="text" name="q" value="<?php echo $this->q; ?>" class="input-medium search-query">
            <button type="submit" class="btn">Tìm kiếm</button>
        </div>
    </form>
    <?php if ($this->q) { ?>
    <div class="alert alert-info">Có <strong><?php echo count($this->books); ?></strong> kết quả tìm kiếm với từ khoá: "<strong><?php echo $this->q; ?></strong>"</div>
    <?php } ?>
	<table class="table table-striped">
        <tr>        
            <th>Tên sách</th>
            <th>Tác giả</th>
            <th>Chuyên mục</th>
            <th>Nhà xuất bản</th>
            <th>Ngày tạo</th>
            <th>Thao tác</th>
        </tr>
        <?php foreach($this->books as $book) { ?>
        <tr id="row-book-id-<?php echo $book['BookID']; ?>">
            <td><a href="<?php echo $this->config->base_path; ?>/librarian/book/edit/book_id/<?php echo $book['BookID']; ?>"><?php echo $book['Title']; ?></a></td>
            <td><?php echo implode(',', array_unique(explode(',', $book['Author']))); ?></td>
            <td><?php echo implode(',', array_unique(explode(',', $book['Category']))); ?></td>            
            <td><?php echo $book['Publisher']; ?></td>
            <td><?php echo date('d/m/Y H:i:s', $book['CreateDate']); ?></td>
            <td><a href="<?php echo $this->config->base_path; ?>/librarian/book/edit/book_id/<?php echo $book['BookID']; ?>">Chỉnh sửa</a> / <a href="javascript: Book.delete(<?php echo $book['BookID']; ?>)" onclick="return confirm('Bạn có chắc chắn muốn xoá sách <?php echo $book['Title']; ?>?');" >Xoá</a></td>
        </tr>
        <?php } ?>
    </table>
    <?php echo $this->pagination; ?>
</fieldset>
<script type="text/javascript">
    var Book = {
	'delete' : function(BookID){		
            $.ajax({
                url: config.base_path + '/librarian/book/delete',
                type: 'post',
                data: {
                    BookID: BookID
                },
                dataType: 'json',					
                success: function(res){
                    if (res.status == 0)
                    {
                        Utils.Message.Error(res.message);
                    }
                    else
                    {
                        $('#row-book-id-' + BookID).remove();
                    }                   
                }
            });
	}
    };
</script>